package cn.cvs.controller;

import cn.cvs.pojo.Role;
import cn.cvs.pojo.SysUser;
import cn.cvs.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping(value = "/role")
public class RoleController {
    @Autowired
    @Qualifier("roleServiceImpl")
    private RoleService roleService;

    @RequestMapping(value = "/list")
    public String list(Model model){
        List<Role> roleList= roleService.list();
        model.addAttribute("roleList",roleList);
        return "sysRole/list";
    }

    @RequestMapping("/toAdd")
    public String toAdd(){
        return "sysRole/add";
    }

    @RequestMapping("/add")
    public String add(Role role){
        int result=roleService.add(role);
        if (result>0){
            return "redirect:/role/list";
        }
        return "sysRole/add";
    }

    @RequestMapping("/toUpdate")
    public String toUpdate(Model model,String id){
        Role sysRole= roleService.getRoleById(id);
        model.addAttribute("sysRole",sysRole);

        return "sysRole/update";
    }
}
